import { getUsers } from '../api/github';
export default {
  getUserName(store, userName) {
    store.commit('getUserName', userName);
  },

  clearUserName(store) {
    store.commit('clearUserName');
  },

  async getUsers(store) {
    //请求前 请求中
    store.commit('beforeReq');
    store.commit('onReq');

    const { items: users } = await getUsers(store.state.userName);
    store.commit('getUsers', users);
    if (users.length > 0) {
      //请求后 有数据
      store.commit('afterReqHasBody');
    } else {
      //请求后 无数据
      store.commit('afterReqNoBody');
    }
  },
};
